import Storage from 'web-storage-cache';
import Url from 'url-parse'

const cache = new Storage({
    storage: 'localStorage',
    exp: 3600
});

let _cache = {};
let url = new Url(document.URL);

_cache.set = function (key, value, options) {
    key += url.pathname;
    cache.set(key, value, options)
};

_cache.delete = function (key) {
    key += url.pathname;
    cache.delete(key)
};

_cache.get = function (key) {
    key += url.pathname;
    return cache.get(key)
};

_cache.clear = function () {
    cache.clear();
};

export default {
    install(Vue) {
        Vue.prototype.$cache = _cache;
        Vue.cache = _cache;
    }
}

export const $cache = _cache;